package com.ruoyi.web.controller.Commerce.info;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.Category;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Dangjian;
import com.ruoyi.system.service.IDangjianService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 党建专栏Controller
 * 
 * @author vv
 * @date 2025-06-26
 */
@RestController
@RequestMapping("/info/dangjian")
public class DangjianController extends BaseController
{
    @Autowired
    private IDangjianService dangjianService;

    /**
     * 查询党建专栏列表
     */
    @PreAuthorize("@ss.hasPermi('info:dangjian:list')")
    @GetMapping("/list")
    public TableDataInfo list(Dangjian dangjian)
    {
        startPage();
        List<Dangjian> list = dangjianService.selectDangjianList(dangjian);
        return getDataTable(list);
    }

    /**
     * 导出党建专栏列表
     */
    @PreAuthorize("@ss.hasPermi('info:dangjian:export')")
    @Log(title = "党建专栏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Dangjian dangjian)
    {
        List<Dangjian> list = dangjianService.selectDangjianList(dangjian);
        ExcelUtil<Dangjian> util = new ExcelUtil<Dangjian>(Dangjian.class);
        util.exportExcel(response, list, "党建专栏数据");
    }

    /**
     * 获取党建专栏详细信息
     */
    @PreAuthorize("@ss.hasPermi('info:dangjian:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(dangjianService.selectDangjianById(id));
    }

    /**
     * 新增党建专栏
     */
    @PreAuthorize("@ss.hasPermi('info:dangjian:add')")
    @Log(title = "党建专栏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Dangjian dangjian)
    {
        return toAjax(dangjianService.insertDangjian(dangjian));
    }

    /**
     * 修改党建专栏
     */
    @PreAuthorize("@ss.hasPermi('info:dangjian:edit')")
    @Log(title = "党建专栏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Dangjian dangjian)
    {
        return toAjax(dangjianService.updateDangjian(dangjian));
    }

    /**
     * 删除党建专栏
     */
    @PreAuthorize("@ss.hasPermi('info:dangjian:remove')")
    @Log(title = "党建专栏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(dangjianService.deleteDangjianByIds(ids));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('info:dangjian:edit')")
    @Log(title = "党建专栏", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult updateDangjianStatus(@RequestBody Dangjian dangjian)
    {

        dangjianService.updateDangjianStatus(dangjian);
        return toAjax(dangjianService.updateDangjianStatus(dangjian));
    }
}
